﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;

public partial class CommonInfoManager_AddressBook : System.Web.UI.Page
{
    List<Position> dept = new PosManager().GetAllPos();
    List< PBOffice.Models.Staff> staff;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            this.AspNetPager1.PageSize = 1;
            this.AspNetPager1.RecordCount = new StaffManager().GetCountByDeptPosName("", "", "");
            staff = new StaffManager().GetAllStaff("", "", "",this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize);
            this.ddlPosition.DataSource = dept;
            this.ddlPosition.DataBind();
            ListItem ll = new ListItem("请选择");
            this.ddlPosition.Items.Insert(0,ll);
            this.GridView1.DataSource = staff;
            this.GridView1.DataBind();
        }


    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        string dep = this.txtDept.Text.Trim();
        string pos = this.ddlPosition.Text.Trim();
        string name = this.txtName.Text.Trim();
        if (dep.Length==0)
        {
            dep = "";
        }
        if (this.ddlPosition.Text == "请选择")
        {
            pos = "";
        }
        if (name.Length==0)
        {
            name = ""; 
        }
        this.AspNetPager1.RecordCount = new StaffManager().GetCountByDeptPosName(dep, pos, name);
        staff=new StaffManager().GetAllStaff(dep,pos,name,this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize);
        this.GridView1.DataSource = staff;
        this.GridView1.DataBind();
        
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string dept = this.txtDept.Text.Trim();
        string name = this.txtName.Text.Trim();
        string pos = this.ddlPosition.Text;
        if (name.Length == 0)
        {
            name = "";
        }
        if (this.ddlPosition.Text == "请选择")
        {
            pos = "";
        }
        if (dept.Length==0)
	{
		 dept="";
	}
        this.AspNetPager1.RecordCount = new StaffManager().GetCountByDeptPosName(dept, pos, name);
        this.GridView1.DataSource =new StaffManager().GetAllStaff(dept,pos,name,this.AspNetPager1.CurrentPageIndex,this.AspNetPager1.PageSize);
        this.GridView1.DataBind();
    }
}